<!DOCTYPE html>



  




<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">
<meta name="baidu-site-verification" content="Hy7lziNO9f" />



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />





  <script>
  (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0f81ff2f.js","daovoice")
  daovoice('init', {
      app_id: "fd041e6e"
    });
  daovoice('update');
  </script>














  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Excel,Python,地理空间分析,数据分析," />





  <link rel="alternate" href="/atom.xml" title="Rsweater's Blog" type="application/atom+xml" />






<meta name="description" content="实验目的： 掌握用Excel、Python进行数据统计描述的方法； 掌握用Excel、Python进行数据标准化的基本方法； 掌握用Excel、Python进行常用数据可视化的方法； 掌握用Excel、Python进行数据连接和数据透视的方法。   实验内容： １.目录： 统计数据描述；   统计数据标准化；     统计数据可视化；   数据连接(VLOOKUP)；   数据透视(Pivot)。">
<meta property="og:type" content="article">
<meta property="og:title" content="实验1——地理数据统计预处理">
<meta property="og:url" content="https://rsweater.github.io/2020/04/18/QG01-Geographic_data_preprocessing/index.html">
<meta property="og:site_name" content="Rsweater&#39;s Blog">
<meta property="og:description" content="实验目的： 掌握用Excel、Python进行数据统计描述的方法； 掌握用Excel、Python进行数据标准化的基本方法； 掌握用Excel、Python进行常用数据可视化的方法； 掌握用Excel、Python进行数据连接和数据透视的方法。   实验内容： １.目录： 统计数据描述；   统计数据标准化；     统计数据可视化；   数据连接(VLOOKUP)；   数据透视(Pivot)。">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/normalization1.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/normalization2.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/Max-Min1.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/Max-Min2.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/mean.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/std1.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/std2.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/ec.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/Excel.png">
<meta property="article:published_time" content="2020-04-18T06:35:00.000Z">
<meta property="article:modified_time" content="2020-04-19T01:37:40.092Z">
<meta property="article:author" content="一线毛衣">
<meta property="article:tag" content="Excel">
<meta property="article:tag" content="Python">
<meta property="article:tag" content="地理空间分析">
<meta property="article:tag" content="数据分析">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/Rsweater/images/master/img/normalization1.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://Rsweater.github.io/2020/04/18/QG01-Geographic_data_preprocessing/"/>





  <title>实验1——地理数据统计预处理 | Rsweater's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?e2c701b7194c8cece405996462a08694";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




<meta name="generator" content="Hexo 4.2.0"></head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <a href="https://github.com/rsweater" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Rsweater's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">最好的状态来源于好的作息！最高的效率来源于好的资源配置！</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://Rsweater.github.io/2020/04/18/QG01-Geographic_data_preprocessing/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="一线毛衣">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Rsweater's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">实验1——地理数据统计预处理</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-04-18T14:35:00+08:00">
                2020-04-18
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E8%AE%A1%E9%87%8F%E5%9C%B0%E7%90%86%E5%AD%A6/" itemprop="url" rel="index">
                    <span itemprop="name">计量地理学</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2020/04/18/QG01-Geographic_data_preprocessing/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2020/04/18/QG01-Geographic_data_preprocessing/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                <span title="字数统计">
                  1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                <span title="阅读时长">
                  4
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="实验目的："><a href="#实验目的：" class="headerlink" title="实验目的："></a>实验目的：</h2><ol>
<li>掌握用Excel、Python进行<strong>数据统计描述</strong>的方法；</li>
<li>掌握用Excel、Python进行<strong>数据标准化</strong>的基本方法；</li>
<li>掌握用Excel、Python进行<strong>常用数据可视化</strong>的方法；</li>
<li>掌握用Excel、Python进行<strong>数据连接</strong>和<strong>数据透视</strong>的方法。</li>
</ol>
<hr>
<h2 id="实验内容："><a href="#实验内容：" class="headerlink" title="实验内容："></a>实验内容：</h2><blockquote>
<h3 id="１-目录："><a href="#１-目录：" class="headerlink" title="１.目录："></a>１.目录：</h3><ol>
<li>统计数据描述；  </li>
<li>统计数据标准化；    </li>
<li>统计数据可视化；  </li>
<li>数据连接(VLOOKUP)；  </li>
<li>数据透视(Pivot)。  </li>
</ol>
</blockquote>
<hr>
<h3 id="2-统计数据描述"><a href="#2-统计数据描述" class="headerlink" title="2. 统计数据描述"></a>2. 统计数据描述</h3><p>1&gt;  集中趋势:  </p>
<table>
<thead>
<tr>
<th align="center">特征</th>
<th align="center">Excel</th>
<th align="center">Python</th>
</tr>
</thead>
<tbody><tr>
<td align="center">平均数</td>
<td align="center">Average函数</td>
<td align="center">np.mean(array)</td>
</tr>
<tr>
<td align="center">中位数</td>
<td align="center">Median函数</td>
<td align="center">np.median(array)</td>
</tr>
<tr>
<td align="center">众数</td>
<td align="center">Mode函数</td>
<td align="center">stats.mode(array)</td>
</tr>
<tr>
<td align="center">2&gt;  离中趋势：</td>
<td align="center"></td>
<td align="center"></td>
</tr>
</tbody></table>
<table>
<thead>
<tr>
<th align="center">特征</th>
<th align="center">Excel</th>
<th align="center">Python</th>
</tr>
</thead>
<tbody><tr>
<td align="center">极差</td>
<td align="center">Max-Min</td>
<td align="center">np.ptp(array)</td>
</tr>
<tr>
<td align="center">方差和标准差</td>
<td align="center">Var和Stdev函数</td>
<td align="center">np.std(array)和 np.var(array)</td>
</tr>
<tr>
<td align="center">变异系数</td>
<td align="center">Stdev/Average</td>
<td align="center">std(array) / mean(array)</td>
</tr>
<tr>
<td align="center">四分位差</td>
<td align="center">Quartile3- Quartile1</td>
<td align="center">np.percentile(array,75)-np.percentile(array,25))</td>
</tr>
</tbody></table>
<p>3&gt; 数据分布特征：  </p>
<table>
<thead>
<tr>
<th align="center">特征</th>
<th align="center">Excel</th>
<th align="center">Python</th>
</tr>
</thead>
<tbody><tr>
<td align="center">偏度系数</td>
<td align="center">Skew函数</td>
<td align="center">st.skew(array)</td>
</tr>
<tr>
<td align="center">峰度系数</td>
<td align="center">Kurt函数</td>
<td align="center">st.kurtosis(array)</td>
</tr>
</tbody></table>
<h3 id="3-统计数据标准化"><a href="#3-统计数据标准化" class="headerlink" title="3. 统计数据标准化"></a>3. 统计数据标准化</h3><p>1&gt; 归一化法  </p>
<img src="https://raw.githubusercontent.com/Rsweater/images/master/img/normalization1.png" width="50%">  

<p>2&gt; 线性比例法/相对值法 </p>
<img src="https://raw.githubusercontent.com/Rsweater/images/master/img/normalization2.png" width="85%">
3> 极差法

<img src="https://raw.githubusercontent.com/Rsweater/images/master/img/Max-Min1.png" width="75%">  
<img src="https://raw.githubusercontent.com/Rsweater/images/master/img/Max-Min2.png" width="85%">  

<p>4&gt; 均值法  </p>
<p><img src="https://raw.githubusercontent.com/Rsweater/images/master/img/mean
.png" width="80%"><br>5&gt; 标准差法  </p>
<p><img src="https://raw.githubusercontent.com/Rsweater/images/master/img/std1
.png" width="80%"><br><img src="https://raw.githubusercontent.com/Rsweater/images/master/img/std2
.png" width="80%"><br>6&gt; 功效系数法 </p>
<p><img src="https://raw.githubusercontent.com/Rsweater/images/master/img/ec
.png" width="90%"><br><strong>Python实现：</strong><br>以极差标准化为例：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据准备</span></span><br><span class="line">arr = np.random.randint(<span class="number">0</span>,<span class="number">100</span>,size=<span class="number">100</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据处理</span></span><br><span class="line">arr_nor = (arr-np.min(arr))/(np.max(arr)-np.min(arr))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据展示</span></span><br><span class="line">print(<span class="string">"原始array：&#123;&#125;\n"</span>.format(arr))</span><br><span class="line">print(<span class="string">"归一化array：&#123;&#125;\n"</span>.format(arr_1))</span><br></pre></td></tr></table></figure>
<h3 id="4-统计数据可视化"><a href="#4-统计数据可视化" class="headerlink" title="4. 统计数据可视化"></a>4. 统计数据可视化</h3><ol>
<li>描述数据<strong>分布</strong>：直方图、箱线图；</li>
<li>描述数据<strong>构成</strong>：饼状图、雷达图；</li>
<li>描述数据<strong>联系</strong>：散点图、相关系数矩阵；</li>
<li>描述数据<strong>比较</strong>：柱状图/条形图、折线图。</li>
</ol>
<h4 id="Excel操作"><a href="#Excel操作" class="headerlink" title="Excel操作:"></a>Excel操作:</h4><img src="https://raw.githubusercontent.com/Rsweater/images/master/img/Excel.png" width="90%">  
#### Python操作： 
以直方图为例：

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据准备</span></span><br><span class="line">np.random.seed(<span class="number">19680801</span>)</span><br><span class="line"></span><br><span class="line">mu, sigma = <span class="number">100</span>, <span class="number">15</span></span><br><span class="line">x = mu + sigma * np.random.randn(<span class="number">10000</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置直方图参数以及展示</span></span><br><span class="line">n, bins, patches = plt.hist(x, <span class="number">50</span>, density=<span class="literal">True</span>, facecolor=<span class="string">'g'</span>, alpha=<span class="number">0.75</span>)</span><br><span class="line"></span><br><span class="line">plt.xlabel(<span class="string">'Smarts'</span>)</span><br><span class="line">plt.ylabel(<span class="string">'Probability'</span>)</span><br><span class="line">plt.title(<span class="string">'Histogram of IQ'</span>)</span><br><span class="line">plt.text(<span class="number">60</span>, <span class="number">.025</span>, <span class="string">r'$\mu=100,\ \sigma=15$'</span>)    <span class="comment"># 添加文本到（60，0.025）</span></span><br><span class="line">plt.axis([<span class="number">40</span>, <span class="number">160</span>, <span class="number">0</span>, <span class="number">0.03</span>])</span><br><span class="line">plt.grid(<span class="literal">True</span>)   <span class="comment"># 配置网格线</span></span><br><span class="line">plt.show()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 箱线图：</span></span><br><span class="line">seaborn.boxplot() 或 plot.box()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 饼状图：</span></span><br><span class="line">matplotlib.pyplot.pie()</span><br><span class="line"><span class="comment"># 雷达图：</span></span><br><span class="line">matplotlib.pyplot.polar()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 散点图：</span></span><br><span class="line">matplotlib.pyplot.scatter() </span><br><span class="line"><span class="comment"># 热力图：</span></span><br><span class="line">seaborn.heatmap()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 条形图：</span></span><br><span class="line">matplotlib.pyplot.bar()   <span class="comment"># 水平</span></span><br><span class="line">matplotlib.pyplot.barh()  <span class="comment"># 垂直</span></span><br><span class="line"><span class="comment"># 折线图：</span></span><br><span class="line">matplotlib.pyplot.plot()</span><br></pre></td></tr></table></figure>

<h3 id="5-数据连接（vlookup"><a href="#5-数据连接（vlookup" class="headerlink" title="5.数据连接（vlookup)"></a>5.数据连接（vlookup)</h3><h4 id="Excel操作："><a href="#Excel操作：" class="headerlink" title="Excel操作："></a>Excel操作：</h4><p>直接使用 = VLOOKUP （你想要查找的内容，要查找的位置，包含要返回的值的区域中的列号，返回近似或精确匹配-表示为 1/TRUE 或 0/假）<br><strong>使用方式：</strong><br>1、选中要连接单元格；<br>2、点击 公式-查找和引用-VLOOKUP 或者 直接 键入=VLOOKUP( ；<br>3、点选要查找的值、包含要返回的值的区域中的列号、返回近似或精确匹配-表示为 1/TRUE 或 0/假。</p>
<h4 id="Python操作："><a href="#Python操作：" class="headerlink" title="Python操作："></a>Python操作：</h4><p>这个方法就很多了。<br>举几个思路：  </p>
<ol>
<li>借助字典方法 dict.get(); </li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">a = &#123;<span class="string">'A'</span>:<span class="number">1</span>, <span class="string">'D'</span>:<span class="number">4</span>, <span class="string">'E'</span>:<span class="number">5</span>&#125;</span><br><span class="line">b = &#123;<span class="string">'A'</span>, <span class="string">'B'</span>, <span class="string">'C'</span>, <span class="string">'D'</span>, <span class="string">'E'</span>&#125;</span><br><span class="line"></span><br><span class="line">c = &#123;k:a.get(k) <span class="keyword">for</span> k <span class="keyword">in</span> b&#125;</span><br><span class="line"></span><br><span class="line">输出：</span><br><span class="line">&#123;<span class="string">'A'</span>: <span class="number">1</span>, <span class="string">'E'</span>: <span class="number">5</span>, <span class="string">'C'</span>: <span class="literal">None</span>, <span class="string">'D'</span>: <span class="number">4</span>, <span class="string">'B'</span>: <span class="literal">None</span>&#125;</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>使用 pandas 空值填充 dataframe.fillna()  </li>
</ol>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据准备</span></span><br><span class="line">frame1 = pd.DataFrame([[<span class="number">1</span>, <span class="number">5.1</span>],[<span class="number">2</span>, <span class="number">5.7</span>],[<span class="number">3</span>, np.nan]],columns=[<span class="string">'id'</span>,<span class="string">'num'</span>])</span><br><span class="line">frame2 = pd.DataFrame([[<span class="number">1</span>, <span class="number">5.1</span>],[<span class="number">2</span>, <span class="number">5.7</span>],[<span class="number">4</span>, <span class="number">9.9</span>],[<span class="number">3</span>,<span class="number">8.8</span>]],columns=[<span class="string">'id'</span>,<span class="string">'num'</span>])</span><br><span class="line"></span><br><span class="line"><span class="comment"># 操作准备</span></span><br><span class="line">frame1 = frame1.set_index(<span class="string">'id'</span>)</span><br><span class="line">frame2 = frame2.set_index(<span class="string">'id'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 数据连接</span></span><br><span class="line">frame3 = frame1.fillna(frame2)</span><br></pre></td></tr></table></figure>
<p>这里需要注意操作准备中设置索引是功能实现的关键，fillna是按索引来填充的。没有的话，对比下面6，7，8行输出：   </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">In [<span class="number">1</span>]: <span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line">In [<span class="number">2</span>]: <span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line">In [<span class="number">3</span>]: frame1 = pd.DataFrame([[<span class="number">1</span>, <span class="number">5.1</span>],[<span class="number">2</span>, <span class="number">5.7</span>],[<span class="number">3</span>, np.nan]],columns=[<span class="string">'id'</span>,<span class="string">'num'</span>])</span><br><span class="line">In [<span class="number">4</span>]: frame2 = pd.DataFrame([[<span class="number">1</span>, <span class="number">5.1</span>],[<span class="number">2</span>, <span class="number">5.7</span>],[<span class="number">4</span>, <span class="number">9.9</span>],[<span class="number">3</span>,<span class="number">8.8</span>]],columns=[<span class="string">'id'</span>,<span class="string">'num'</span>])</span><br><span class="line">In [<span class="number">5</span>]: frame3 = frame1.fillna(frame2)</span><br><span class="line"></span><br><span class="line">In [<span class="number">6</span>]: frame1</span><br><span class="line">Out[<span class="number">6</span>]:</span><br><span class="line">   id  num</span><br><span class="line"><span class="number">0</span>   <span class="number">1</span>  <span class="number">5.1</span></span><br><span class="line"><span class="number">1</span>   <span class="number">2</span>  <span class="number">5.7</span></span><br><span class="line"><span class="number">2</span>   <span class="number">3</span>  NaN</span><br><span class="line">In [<span class="number">7</span>]: frame2</span><br><span class="line">Out[<span class="number">7</span>]:</span><br><span class="line">   id  num</span><br><span class="line"><span class="number">0</span>   <span class="number">1</span>  <span class="number">5.1</span></span><br><span class="line"><span class="number">1</span>   <span class="number">2</span>  <span class="number">5.7</span></span><br><span class="line"><span class="number">2</span>   <span class="number">4</span>  <span class="number">9.9</span></span><br><span class="line"><span class="number">3</span>   <span class="number">3</span>  <span class="number">8.8</span></span><br><span class="line">In [<span class="number">8</span>]: frame3</span><br><span class="line">Out[<span class="number">8</span>]:</span><br><span class="line">   id  num</span><br><span class="line"><span class="number">0</span>   <span class="number">1</span>  <span class="number">5.1</span></span><br><span class="line"><span class="number">1</span>   <span class="number">2</span>  <span class="number">5.7</span></span><br><span class="line"><span class="number">2</span>   <span class="number">3</span>  <span class="number">9.9</span></span><br><span class="line"></span><br><span class="line">In [<span class="number">9</span>]: frame1 = frame1.set_index(<span class="string">'id'</span>)</span><br><span class="line">In [<span class="number">10</span>]: frame2 = frame2.set_index(<span class="string">'id'</span>)</span><br><span class="line">In [<span class="number">11</span>]: frame3 = frame1.fillna(frame2)</span><br><span class="line"></span><br><span class="line">In [<span class="number">12</span>]: frame3</span><br><span class="line">Out[<span class="number">12</span>]:</span><br><span class="line">id   num</span><br><span class="line"><span class="number">1</span>    <span class="number">5.1</span></span><br><span class="line"><span class="number">2</span>    <span class="number">5.7</span></span><br><span class="line"><span class="number">3</span>    <span class="number">8.8</span></span><br></pre></td></tr></table></figure>
<h3 id="6-数据透视（pivot"><a href="#6-数据透视（pivot" class="headerlink" title="6.数据透视（pivot)"></a>6.数据透视（pivot)</h3>
      
    </div>
    
    
    

    <div>
      
        
      
    </div>

    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>
      
    </div>
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Excel/" rel="tag"><i class="fa fa-tag"></i> Excel</a>
          
            <a href="/tags/Python/" rel="tag"><i class="fa fa-tag"></i> Python</a>
          
            <a href="/tags/%E5%9C%B0%E7%90%86%E7%A9%BA%E9%97%B4%E5%88%86%E6%9E%90/" rel="tag"><i class="fa fa-tag"></i> 地理空间分析</a>
          
            <a href="/tags/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90/" rel="tag"><i class="fa fa-tag"></i> 数据分析</a>
          
        </div>
      

      
      
        <div class="post-widgets">
        

        

        
          
          <div id="needsharebutton-postbottom">
            <span class="btn">
              <i class="fa fa-share-alt" aria-hidden="true"></i>
            </span>
          </div>
        
        </div>
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/03/29/hello-world/" rel="next" title="Hello World">
                <i class="fa fa-chevron-left"></i> Hello World
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/04/21/RS02-Evaluation_of_image_fusion/" rel="prev" title="图像融合质量评价指标">
                图像融合质量评价指标 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="一线毛衣" />
            
              <p class="site-author-name" itemprop="name">一线毛衣</p>
              <p class="site-description motion-element" itemprop="description">这里有Python、GIS相关的小笔记！</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/%7C%7C%20archive">
              
                  <span class="site-state-item-count">7</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">5</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">11</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/rsweater" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:bw_chen1223@foxmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#实验目的："><span class="nav-number">1.</span> <span class="nav-text">实验目的：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#实验内容："><span class="nav-number">2.</span> <span class="nav-text">实验内容：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#１-目录："><span class="nav-number">2.1.</span> <span class="nav-text">１.目录：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-统计数据描述"><span class="nav-number">2.2.</span> <span class="nav-text">2. 统计数据描述</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-统计数据标准化"><span class="nav-number">2.3.</span> <span class="nav-text">3. 统计数据标准化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-统计数据可视化"><span class="nav-number">2.4.</span> <span class="nav-text">4. 统计数据可视化</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Excel操作"><span class="nav-number">2.4.1.</span> <span class="nav-text">Excel操作:</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-数据连接（vlookup"><span class="nav-number">2.5.</span> <span class="nav-text">5.数据连接（vlookup)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#Excel操作："><span class="nav-number">2.5.1.</span> <span class="nav-text">Excel操作：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Python操作："><span class="nav-number">2.5.2.</span> <span class="nav-text">Python操作：</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-数据透视（pivot"><span class="nav-number">2.6.</span> <span class="nav-text">6.数据透视（pivot)</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一线毛衣</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>




<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共7.6k字</span>
</div>
        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  

  
</div>





  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=66540970";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  









  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three-waves.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'n0m507S9Q3hGB7na3rXQO8bH-gzGzoHsz',
        appKey: 'nBz9lyUQ5ooRmJcE8qaIVUym',
        placeholder: 'ヾﾉ≧∀≦)o来啊，快活啊!',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  
  
  <link rel="stylesheet" href="/lib/needsharebutton/needsharebutton.css">

  
  
  <script src="/lib/needsharebutton/needsharebutton.js"></script>

  <script>
    
      pbOptions = {};
      
          pbOptions.iconStyle = "box";
      
          pbOptions.boxForm = "horizontal";
      
          pbOptions.position = "bottomCenter";
      
          pbOptions.networks = "Weibo,Wechat,Douban,QQZone,Twitter,Facebook";
      
      new needShareButton('#needsharebutton-postbottom', pbOptions);
    
    
  </script>

  

  
  


  

  

  
<!-- 代码块复制功能 -->
<script type="text/javascript" src="/js/src/clipboard.min.js"></script>  
<script type="text/javascript" src="/js/src/clipboard-use.js"></script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","model":{"jsonPath":"live2d-widget-model-wanko"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false,"tagMode":false});</script></body>
</html>
